<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>【ES6】ES6语法 | ChenWeiHui's Blog</title><meta name="author" content="cwh"><meta name="copyright" content="cwh"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="let定义变量1、变量不可重复声明 12let star &#x3D; &amp;#x27;苹果&amp;#x27; let star &#x3D; &amp;#x27;瓶子&amp;#x27;&#x2F;&#x2F;报错  2、块级作用域 大括号内都属于作用域内 1&amp;#123; let girl &#x3D; &amp;#x27;周扬青&amp;#x27; &amp;#125;  3、不存在变量提升 var命令会发生”变量提升“现象，即变量可以在声明之前使用，值为undefined。 12conso">
<meta property="og:type" content="article">
<meta property="og:title" content="【ES6】ES6语法">
<meta property="og:url" content="https://gitee.com/CWH6/2023/05/10/%E3%80%90ES6%E3%80%91ES6%E8%AF%AD%E6%B3%95/index.html">
<meta property="og:site_name" content="ChenWeiHui&#39;s Blog">
<meta property="og:description" content="let定义变量1、变量不可重复声明 12let star &#x3D; &amp;#x27;苹果&amp;#x27; let star &#x3D; &amp;#x27;瓶子&amp;#x27;&#x2F;&#x2F;报错  2、块级作用域 大括号内都属于作用域内 1&amp;#123; let girl &#x3D; &amp;#x27;周扬青&amp;#x27; &amp;#125;  3、不存在变量提升 var命令会发生”变量提升“现象，即变量可以在声明之前使用，值为undefined。 12conso">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png">
<meta property="article:published_time" content="2023-05-10T10:30:26.000Z">
<meta property="article:modified_time" content="2023-06-12T16:37:27.962Z">
<meta property="article:author" content="cwh">
<meta property="article:tag" content="ES6">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png"><link rel="shortcut icon" href="/bk/img/jljy3.png"><link rel="canonical" href="https://gitee.com/CWH6/2023/05/10/%E3%80%90ES6%E3%80%91ES6%E8%AF%AD%E6%B3%95/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/bk/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/bk/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '【ES6】ES6语法',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-06-13 00:37:27'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 5.4.2"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/bk/archives/"><div class="headline">Articles</div><div class="length-num">66</div></a><a href="/bk/tags/"><div class="headline">Tags</div><div class="length-num">33</div></a><a href="/bk/categories/"><div class="headline">Categories</div><div class="length-num">8</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/bk/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/bk/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/bk/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/bk/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/bk/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/bk/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bk/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/bk/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/bk/img/alone_blue_sky.jpg')"><nav id="nav"><span id="blog-info"><a href="/bk/" title="ChenWeiHui's Blog"><span class="site-name">ChenWeiHui's Blog</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/bk/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/bk/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/bk/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/bk/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> List</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/bk/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/bk/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/bk/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/bk/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">【ES6】ES6语法</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2023-05-10T10:30:26.000Z" title="Created 2023-05-10 18:30:26">2023-05-10</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2023-06-12T16:37:27.962Z" title="Updated 2023-06-13 00:37:27">2023-06-13</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/bk/categories/%E5%89%8D%E7%AB%AF/">前端</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="【ES6】ES6语法"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="let定义变量"><a href="#let定义变量" class="headerlink" title="let定义变量"></a>let定义变量</h2><p><strong>1、变量不可重复声明</strong></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> star = <span class="string">&#x27;苹果&#x27;</span> </span><br><span class="line"><span class="keyword">let</span> star = <span class="string">&#x27;瓶子&#x27;</span><span class="comment">//报错</span></span><br></pre></td></tr></table></figure>

<p><strong>2、块级作用域</strong></p>
<p>大括号内都属于作用域内</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123; <span class="type">let</span> <span class="variable">girl</span> <span class="operator">=</span> <span class="string">&#x27;周扬青&#x27;</span> &#125;</span><br></pre></td></tr></table></figure>

<p><strong>3、不存在变量提升</strong></p>
<p><code>var</code>命令会发生”变量提升“现象，即变量可以在声明之前使用，值为<code>undefined</code>。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num) <span class="comment">// undefined</span></span><br><span class="line"><span class="keyword">var</span> num = <span class="number">1</span></span><br></pre></td></tr></table></figure>

<p><code>let</code>命令不存在变量提升的行为，它所声明的变量一定要在声明后使用，否则报错。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(num) <span class="comment">// Cannot access &#x27;num&#x27; before initialization</span></span><br><span class="line"><span class="keyword">var</span> num = <span class="number">1</span></span><br></pre></td></tr></table></figure>

<p><strong>4.不影响作用域链</strong></p>
<h2 id="const-关键字"><a href="#const-关键字" class="headerlink" title="const 关键字"></a>const 关键字</h2><p><strong>1、声明必须赋初始值</strong> </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="variable constant_">ONE</span> = <span class="number">1</span>;</span><br></pre></td></tr></table></figure>

<p><strong>2、标识符一般为大写</strong> </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="variable constant_">ONE</span> = <span class="number">1</span>;</span><br></pre></td></tr></table></figure>

<p><strong>3、常量值不能修改</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="variable constant_">ONE</span> = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="variable constant_">ONE</span> = <span class="number">0</span>; <span class="comment">//报错</span></span><br></pre></td></tr></table></figure>

<p><strong>4、块儿级作用域</strong> </p>
<p><strong>5. 对于数组和对象的元素修改, 不算做对常量的修改, 不会报错</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="variable constant_">TEAM</span> = [<span class="string">&#x27;UZI&#x27;</span>,<span class="string">&#x27;MXLG&#x27;</span>,<span class="string">&#x27;Ming&#x27;</span>,<span class="string">&#x27;Letme&#x27;</span>];</span><br><span class="line"><span class="variable constant_">TEAM</span>.<span class="title function_">push</span>(<span class="string">&#x27;Meiko&#x27;</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable constant_">TEAM</span>);<span class="comment">//[ &#x27;UZI&#x27;, &#x27;MXLG&#x27;, &#x27;Ming&#x27;, &#x27;Letme&#x27;, &#x27;Meiko&#x27; ]</span></span><br></pre></td></tr></table></figure>



<h2 id="结构赋值"><a href="#结构赋值" class="headerlink" title="结构赋值"></a>结构赋值</h2><p>ES6 允许按照一定模式，从数组和对象中提取值，对变量进行赋值，这被称为解构赋值。</p>
<p><strong>数组的解构赋值</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr = [<span class="string">&#x27;张学友&#x27;</span>, <span class="string">&#x27;刘德华&#x27;</span>, <span class="string">&#x27;黎明&#x27;</span>, <span class="string">&#x27;郭富城&#x27;</span>];</span><br><span class="line"><span class="keyword">let</span> [zhang, liu, li, guo] = arr;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(zhang); <span class="comment">// 张学友</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(liu); <span class="comment">// 刘德华</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(li); <span class="comment">// 黎明</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(guo); <span class="comment">// 郭富城</span></span><br></pre></td></tr></table></figure>



<p><strong>对象的解构赋值</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> lin = &#123;</span><br><span class="line">  <span class="attr">name</span>: <span class="string">&#x27;林志颖&#x27;</span>,</span><br><span class="line">  <span class="attr">tags</span>: [<span class="string">&#x27;车手&#x27;</span>, <span class="string">&#x27;歌手&#x27;</span>, <span class="string">&#x27;小旋风&#x27;</span>, <span class="string">&#x27;演员&#x27;</span>]</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">let</span> &#123; name, tags &#125; = lin;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(name); <span class="comment">// &#x27;林志颖&#x27;</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(tags); <span class="comment">// [&#x27;车手&#x27;, &#x27;歌手&#x27;, &#x27;小旋风&#x27;, &#x27;演员&#x27;]</span></span><br></pre></td></tr></table></figure>



<p><strong>复杂的解构</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> wangfei = &#123; </span><br><span class="line"> <span class="attr">name</span>: <span class="string">&#x27;王菲&#x27;</span>, </span><br><span class="line"> <span class="attr">age</span>: <span class="number">18</span>, </span><br><span class="line"> <span class="attr">songs</span>: [<span class="string">&#x27;红豆&#x27;</span>, <span class="string">&#x27;流年&#x27;</span>, <span class="string">&#x27;暧昧&#x27;</span>, <span class="string">&#x27;传奇&#x27;</span>], </span><br><span class="line"> <span class="attr">history</span>: [ </span><br><span class="line"> &#123;<span class="attr">name</span>: <span class="string">&#x27;窦唯&#x27;</span>&#125;, </span><br><span class="line"> &#123;<span class="attr">name</span>: <span class="string">&#x27;李亚鹏&#x27;</span>&#125;, </span><br><span class="line"> &#123;<span class="attr">name</span>: <span class="string">&#x27;谢霆锋&#x27;</span>&#125; </span><br><span class="line"> ] </span><br><span class="line">&#125;; </span><br><span class="line"><span class="keyword">let</span> &#123;<span class="attr">songs</span>: [one, two, three], <span class="attr">history</span>: [first, second, third]&#125; = wangfei; </span><br></pre></td></tr></table></figure>



<h2 id="模板字符串"><a href="#模板字符串" class="headerlink" title="模板字符串"></a>模板字符串</h2><p>模板字符串（template string）是增强版的字符串，用反引号（`）标识，特点： </p>
<p>1)字符串中可以出现换行符 </p>
<p>2)可以使用 ${xxx} 形式输出变量 </p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 定义字符串 </span></span><br><span class="line"><span class="keyword">let</span> str = <span class="string">`&lt;ul&gt; </span></span><br><span class="line"><span class="string">            &lt;li&gt;魔道&lt;/li&gt; </span></span><br><span class="line"><span class="string">            &lt;li&gt;小天才&lt;/li&gt; </span></span><br><span class="line"><span class="string">            &lt;li&gt;星守&lt;/li&gt; </span></span><br><span class="line"><span class="string">            &lt;li&gt;护卫&lt;/li&gt; </span></span><br><span class="line"><span class="string">           &lt;/ul&gt;`</span>;</span><br></pre></td></tr></table></figure>

<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 变量拼接 </span></span><br><span class="line"><span class="type">let</span> <span class="variable">star</span> <span class="operator">=</span> <span class="string">&#x27;王宁&#x27;</span>;</span><br><span class="line"><span class="type">let</span> <span class="variable">result</span> <span class="operator">=</span> `$&#123;star&#125;在前几年离开了开心麻花`;</span><br><span class="line">console.log(result); <span class="comment">// 王宁在前几年离开了开心麻花</span></span><br></pre></td></tr></table></figure>



<h2 id="简化对象写法"><a href="#简化对象写法" class="headerlink" title="简化对象写法"></a>简化对象写法</h2><p>ES6 允许在大括号里面，直接写入变量和函数，作为对象的属性和方法。这样的书写更加简洁。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">let</span> <span class="variable">name</span> <span class="operator">=</span> <span class="string">&#x27;XATU&#x27;</span>;</span><br><span class="line"><span class="type">let</span> <span class="variable">slogon</span> <span class="operator">=</span> <span class="string">&#x27;永远追求教育更高标准&#x27;</span>;</span><br><span class="line"><span class="type">let</span> <span class="variable">improve</span> <span class="operator">=</span> function () &#123;</span><br><span class="line">   console.log(<span class="string">&#x27;可以提高你的技能&#x27;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//属性和方法简写 </span></span><br><span class="line"><span class="type">let</span> <span class="variable">atguigu</span> <span class="operator">=</span> &#123;</span><br><span class="line">       name,</span><br><span class="line">       slogon,</span><br><span class="line">      improve,</span><br><span class="line">      change() &#123;</span><br><span class="line">          console.log(<span class="string">&#x27;可以改变你&#x27;</span>)</span><br><span class="line">      &#125;</span><br><span class="line">  &#125;;</span><br><span class="line"> console.log(atguigu);</span><br></pre></td></tr></table></figure>



<h2 id="箭头函数"><a href="#箭头函数" class="headerlink" title="箭头函数"></a>箭头函数</h2><p>ES6 允许使用「箭头」（**=&gt;**）定义函数。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">let</span> <span class="variable">fn</span> <span class="operator">=</span> (arg1, arg2, arg3) =&gt; &#123;</span><br><span class="line">     <span class="keyword">return</span> arg1 + arg2 + arg3;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<p><strong>1、如果形参只有一个，则小括号可以省略</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="title function_">fn</span> = str=&gt; &#123;</span><br><span class="line">    <span class="keyword">return</span> str;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">fn</span>(<span class="string">&quot;helloworld&quot;</span>));<span class="comment">// helloworld</span></span><br></pre></td></tr></table></figure>



<p><strong>2、函数体如果只有一条语句，则花括号可以省略，函数的返回值为该条语句的执行结果</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="title function_">fn</span> = str=&gt; str;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">fn</span>(<span class="string">&quot;cat&quot;</span>));<span class="comment">// cat</span></span><br></pre></td></tr></table></figure>



<p><strong>3、箭头函数 this 指向声明时所在作用域下 this 的值</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// this 是静态的. this 始终指向函数声明时所在作用域下的 this 的值</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getName</span>(<span class="params"></span>) &#123;</span><br><span class="line">   <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">this</span>.<span class="property">name</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 设置 window 对象的 name 属性</span></span><br><span class="line"><span class="variable language_">window</span>.<span class="property">name</span> = <span class="string">&#x27;XATU&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 直接调用</span></span><br><span class="line"><span class="title function_">getName</span>(); <span class="comment">// XATU</span></span><br></pre></td></tr></table></figure>



<p><strong>4、箭头函数不能作为构造函数实例化</strong></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="title function_">Person</span> = (<span class="params">name, age</span>) =&gt; &#123;</span><br><span class="line">     <span class="variable language_">this</span>.<span class="property">name</span> = name;</span><br><span class="line">     <span class="variable language_">this</span>.<span class="property">age</span> = age;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> me = <span class="keyword">new</span> <span class="title class_">Person</span>(<span class="string">&#x27;xiao&#x27;</span>,<span class="number">30</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(me);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 报错 Uncaught TypeError: Person is not a constructor</span></span><br></pre></td></tr></table></figure>



<p><strong>5、不能使用 arguments</strong></p>
 <figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="title function_">fn</span> = (<span class="params"></span>) =&gt; &#123;</span><br><span class="line">     <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">arguments</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">fn</span>(<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 报错 Uncaught ReferenceError: arguments is not defined</span></span><br></pre></td></tr></table></figure>



<h2 id="rest参数"><a href="#rest参数" class="headerlink" title="rest参数"></a>rest参数</h2><p>ES6 引入 <em>rest</em> 参数（形式为 …变量名），用于获取函数的多余参数，这样就不需要使用<em>arguments</em>对象了。<em>rest</em> 参数搭配的变量是一个<strong>数组</strong>，该变量将多余的参数放入数组中。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">function <span class="title function_">add</span><span class="params">(...args)</span> &#123;</span><br><span class="line">  console.log(args);</span><br><span class="line">&#125;</span><br><span class="line"><span class="type">let</span> <span class="variable">str</span> <span class="operator">=</span> add(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>);</span><br><span class="line">console.log(str);<span class="comment">// [1, 2, 3, 4, 5]</span></span><br></pre></td></tr></table></figure>



<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">add</span>(<span class="params">...values</span>) &#123;</span><br><span class="line">   <span class="keyword">let</span> sum = <span class="number">0</span>;</span><br><span class="line">   <span class="keyword">for</span> (<span class="keyword">var</span> k <span class="keyword">of</span> values) &#123;</span><br><span class="line">      sum += k;</span><br><span class="line">   &#125;</span><br><span class="line">  <span class="keyword">return</span> sum;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">let</span> str = <span class="title function_">add</span>(<span class="number">2</span>, <span class="number">5</span>, <span class="number">3</span>) </span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(str);<span class="comment">// 10</span></span><br></pre></td></tr></table></figure>



<p>arguments对象不是数组，而是一个类似数组的对象。所以为了使用数组的方法，必须使用Array.prototype.slice.call先将其转为数组。rest 参数就不存在这个问题，它就是一个真正的数组，数组特有的方法都可以使用。</p>
<p>下面是一个利用 rest 参数改写数组push方法的例子。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">push</span>(<span class="params">arr, ...items</span>) &#123;</span><br><span class="line">        items.<span class="title function_">forEach</span>(<span class="keyword">function</span> (<span class="params">item</span>) &#123;</span><br><span class="line">          arr.<span class="title function_">push</span>(item);</span><br><span class="line">          <span class="variable language_">console</span>.<span class="title function_">log</span>(item);</span><br><span class="line">     &#125;);</span><br><span class="line">   &#125;</span><br><span class="line"><span class="keyword">var</span> a = [];</span><br><span class="line"><span class="title function_">push</span>(a, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>);</span><br></pre></td></tr></table></figure>

<p><em>rest</em> 参数必须是<strong>最后一个形参</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">function</span> <span class="title function_">minus</span>(<span class="params">a, b, ...args</span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(a, b, args);</span><br><span class="line">&#125;</span><br><span class="line"><span class="title function_">minus</span>(<span class="number">100</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>, <span class="number">19</span>); <span class="comment">// 100 , 1 , [2, 3, 4, 5, 19]</span></span><br></pre></td></tr></table></figure>

<h2 id="spread-拓展运算符"><a href="#spread-拓展运算符" class="headerlink" title="spread 拓展运算符"></a>spread 拓展运算符</h2><p>扩展运算符（spread）也是三个点（…）。它好比 rest 参数的逆运算，将一个数组转为用逗号分隔的参数序列，对数组进行解包。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> tfboys = [<span class="string">&#x27;德玛西亚之力&#x27;</span>, <span class="string">&#x27;德玛西亚之翼&#x27;</span>, <span class="string">&#x27;德玛西亚皇子&#x27;</span>];</span><br><span class="line"><span class="keyword">function</span> <span class="title function_">fn</span>(<span class="params"></span>) &#123;</span><br><span class="line">   <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="variable language_">arguments</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="title function_">fn</span>(...tfboys)</span><br></pre></td></tr></table></figure>

<p><strong>数组合并</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> arr1 = [<span class="string">&#x27;a&#x27;</span>, <span class="string">&#x27;b&#x27;</span>];</span><br><span class="line"><span class="keyword">const</span> arr2 = [<span class="string">&#x27;c&#x27;</span>];</span><br><span class="line"><span class="keyword">const</span> arr3 = [<span class="string">&#x27;d&#x27;</span>, <span class="string">&#x27;e&#x27;</span>];</span><br><span class="line"><span class="comment">// ES5 的合并数组</span></span><br><span class="line">arr1.<span class="title function_">concat</span>(arr2, arr3);</span><br><span class="line"><span class="comment">// [ &#x27;a&#x27;, &#x27;b&#x27;, &#x27;c&#x27;, &#x27;d&#x27;, &#x27;e&#x27; ]</span></span><br><span class="line"><span class="comment">// ES6 的合并数组</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>([...arr1, ...arr2, ...arr3]);</span><br><span class="line"><span class="comment">// [ &#x27;a&#x27;, &#x27;b&#x27;, &#x27;c&#x27;, &#x27;d&#x27;, &#x27;e&#x27; ]</span></span><br></pre></td></tr></table></figure>

<p><strong>对象合并</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">let</span> <span class="variable">b</span> <span class="operator">=</span> &#123; name: <span class="string">&#x27;aaa&#x27;</span>, age: <span class="number">19</span> &#125;</span><br><span class="line">console.log(b) <span class="comment">// &#123; name: &#x27;aaa&#x27;, age: 19 &#125;</span></span><br><span class="line"><span class="type">let</span> <span class="variable">a</span> <span class="operator">=</span> &#123; hobby: <span class="string">&#x27;game&#x27;</span>, ...b &#125;</span><br><span class="line">console.log(a) <span class="comment">// &#123; hobby: &#x27;game&#x27;, name: &#x27;aaa&#x27;, age: 19 &#125;</span></span><br></pre></td></tr></table></figure>



<p><strong>与解构赋值结合：</strong></p>
<p>扩展运算符可以与<strong>解构赋值结合</strong>起来，用于生成数组。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">const [first, ...rest] = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];</span><br><span class="line">console.log(first); <span class="comment">// 1</span></span><br><span class="line">console.log(rest); <span class="comment">// [2, 3, 4, 5]</span></span><br></pre></td></tr></table></figure>

<p>如果将扩展运算符用于数组赋值，只能放在参数的<strong>最后一位</strong>，否则会报错。</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> [...butLast, last1] = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];<span class="comment">// 报错</span></span><br><span class="line"><span class="keyword">const</span> [first, ...middle, last2] = [<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>, <span class="number">5</span>];<span class="comment">// 报错</span></span><br></pre></td></tr></table></figure>



<h2 id="for…of循环"><a href="#for…of循环" class="headerlink" title="for…of循环"></a>for…of循环</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="title class_">Uname</span> = [<span class="string">&quot;搜到&quot;</span>, <span class="string">&quot;的撒&quot;</span>, <span class="string">&quot;的风格&quot;</span>, <span class="string">&quot;范德萨&quot;</span>, <span class="string">&quot;公司发&quot;</span>, <span class="string">&quot;告诉对方&quot;</span>];</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">let</span> a <span class="keyword">of</span> <span class="title class_">Uname</span>) &#123;</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">log</span>(a);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="Promise对象"><a href="#Promise对象" class="headerlink" title="Promise对象"></a>Promise对象</h2><p>是es6引入的异步编程新的解决方案。用来封装异步操作并且可以获取其成功或者失败的结果,promise是一个对象，对象和函数的区别就是对象可以保存状态，函数不可以（闭包除外）</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> p = <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve,reject</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="built_in">setTimeout</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">        <span class="keyword">const</span> data = <span class="string">&#x27;大奥古斯&#x27;</span></span><br><span class="line">        <span class="title function_">resolve</span>(data)</span><br><span class="line">    &#125;,<span class="number">4000</span>)</span><br><span class="line">&#125;).<span class="title function_">then</span>(<span class="function">(<span class="params">value</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(value)</span><br><span class="line">&#125;,<span class="function">(<span class="params">reason</span>)=&gt;</span>&#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(reason)</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<h2 id="set-集合"><a href="#set-集合" class="headerlink" title="set 集合"></a>set 集合</h2><p>set:ES6提供了新的数据结构set（集合），它类似于数组，但成员的值都是唯一的，集合实现了 iterator接口，所以可以使用扩展运算符和for of进行遍历，</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//声明一个set</span></span><br><span class="line"><span class="keyword">let</span> se = <span class="keyword">new</span> <span class="title class_">Set</span>();</span><br><span class="line"><span class="keyword">let</span> se2 = <span class="keyword">new</span> <span class="title class_">Set</span>([<span class="string">&quot;da&quot;</span>, <span class="string">&quot;xiao&quot;</span>, <span class="string">&quot;gao&quot;</span>, <span class="string">&quot;pang&quot;</span>]);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(se2);</span><br><span class="line"><span class="comment">//添加新元素</span></span><br><span class="line">se2.<span class="title function_">add</span>(<span class="string">&quot;xishi&quot;</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(se2);</span><br><span class="line"><span class="comment">//删除元素</span></span><br><span class="line">se2.<span class="title function_">delete</span>(<span class="string">&quot;gao&quot;</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(se2);</span><br><span class="line"><span class="comment">//检测</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(se2.<span class="title function_">has</span>(<span class="string">&quot;da&quot;</span>));</span><br><span class="line"><span class="comment">//清空</span></span><br><span class="line">se2.<span class="title function_">clear</span>();</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(se2);</span><br></pre></td></tr></table></figure>



<h2 id="Map"><a href="#Map" class="headerlink" title="Map"></a>Map</h2><p>ES6提供了数据结构Map，它类似于对象，也是键值对的集合。但键的范围不限于字符串，各种类型的值（包括对象）都可以当做键。Map也实现了iterator接口，所以可以使用扩展运算符和for of进行遍历</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//声明一个Map</span></span><br><span class="line"><span class="keyword">let</span> m = <span class="keyword">new</span> <span class="title class_">Map</span>();</span><br><span class="line">m.<span class="title function_">set</span>(<span class="string">&quot;name&quot;</span>, <span class="string">&quot;zmy&quot;</span>);</span><br><span class="line">m.<span class="title function_">set</span>(<span class="string">&quot;change&quot;</span>, <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">11111</span>);</span><br><span class="line">&#125;);</span><br><span class="line"><span class="keyword">let</span> key = &#123;</span><br><span class="line"><span class="attr">school</span>: <span class="string">&quot;ahgy&quot;</span>,</span><br><span class="line">&#125;;</span><br><span class="line">m.<span class="title function_">set</span>(key, <span class="string">&quot;mm&quot;</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(m);</span><br><span class="line"><span class="comment">//size</span></span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(m.<span class="property">size</span>);</span><br><span class="line"><span class="comment">//其中 键值 可以是字符串，也可以是对象</span></span><br></pre></td></tr></table></figure>

<p>输出</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="title class_">Map</span>(<span class="number">3</span>) &#123;</span><br><span class="line">  <span class="string">&#x27;name&#x27;</span> =&gt; <span class="string">&#x27;zmy&#x27;</span>,</span><br><span class="line">  <span class="string">&#x27;change&#x27;</span> =&gt; [<span class="title class_">Function</span> (anonymous)],</span><br><span class="line">  &#123; <span class="attr">school</span>: <span class="string">&#x27;ahgy&#x27;</span> &#125; =&gt; <span class="string">&#x27;mm&#x27;</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="number">3</span></span><br></pre></td></tr></table></figure>



<h2 id="Class类"><a href="#Class类" class="headerlink" title="Class类"></a>Class类</h2><p>通过class，可以定义类。基本上es6中可以看作是一个语法糖，新的class写法只是让对象原型的写法更加清晰、更加面向对象编程的语法而已。</p>
<p>类似于java的语法</p>
<p>(1) class声明类，<br>(2) constructor定义构造函数初始化，当使用new 方法名()，就会执行constructor<br>(3) extends继承父类，<br>(4) super调用父级构造方法，<br>(5) static定义静态方法和属性，<br>(6) 父类方法可以重写</p>
<p><strong>定义类构造函数，实例化类</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">phone</span> &#123;</span><br><span class="line">    <span class="comment">//构造方法，名字不能修改</span></span><br><span class="line">    <span class="title function_">constructor</span>(<span class="params">price, name</span>) &#123;</span><br><span class="line">      <span class="variable language_">this</span>.<span class="property">price</span> = price;</span><br><span class="line">      <span class="variable language_">this</span>.<span class="property">name</span> = name;</span><br><span class="line">    &#125;</span><br><span class="line">	<span class="comment">//方法必须使用该语法，不能使用es5对象完整形式call：function&#123;&#125;</span></span><br><span class="line">    <span class="title function_">call</span>(<span class="params"></span>) &#123;</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;打电话&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">let</span> oneplus = <span class="keyword">new</span> <span class="title function_">phone</span>(<span class="number">2000</span>, <span class="string">&quot;华为&quot;</span>);</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(oneplus);<span class="comment">// phone &#123; price: 2000, name: &#x27;华为&#x27; &#125;</span></span><br></pre></td></tr></table></figure>

<p><strong>class静态成员</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">phone</span>&#123;</span><br><span class="line">  <span class="keyword">static</span> num = <span class="number">123</span></span><br><span class="line">  <span class="keyword">static</span> <span class="title function_">change</span>(<span class="params"></span>)&#123;</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;我可以改变世界&#x27;</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>构造函数继承</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">class</span> <span class="title class_">Phone</span> &#123;</span><br><span class="line">  <span class="comment">//构造方法</span></span><br><span class="line">  <span class="title function_">constructor</span>(<span class="params">price, name</span>) &#123;</span><br><span class="line">      <span class="variable language_">this</span>.<span class="property">price</span> = price</span><br><span class="line">      <span class="variable language_">this</span>.<span class="property">name</span> = name</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="title function_">calll</span>(<span class="params"></span>) &#123;</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;我可以改变世界&#x27;</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">class</span> <span class="title class_">smallcall</span> <span class="keyword">extends</span> <span class="title class_ inherited__">Phone</span> &#123;</span><br><span class="line">  <span class="comment">//构造方法</span></span><br><span class="line">  <span class="title function_">constructor</span>(<span class="params">price, name, color, size</span>) &#123;</span><br><span class="line">      <span class="variable language_">super</span>(price, name) <span class="comment">//调用父类的constructor方法</span></span><br><span class="line">      <span class="variable language_">this</span>.<span class="property">color</span> = color</span><br><span class="line">      <span class="variable language_">this</span>.<span class="property">size</span> = size</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="title function_">photo</span>(<span class="params"></span>) &#123;</span><br><span class="line">      <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;111&#x27;</span>)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">const</span> mi = <span class="keyword">new</span> <span class="title function_">smallcall</span>(<span class="number">133</span>, <span class="string">&#x27;小米&#x27;</span>, <span class="string">&#x27;red&#x27;</span>, <span class="number">4.7</span>)</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(mi);<span class="comment">// smallcall &#123; price: 133, name: &#x27;小米&#x27;, color: &#x27;red&#x27;, size: 4.7 &#125;</span></span><br></pre></td></tr></table></figure>

<h2 id="数值拓展"><a href="#数值拓展" class="headerlink" title="数值拓展"></a>数值拓展</h2><p><strong>1.Number.EPSILON:是JavaScript表示的最小精度</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Number</span>.<span class="property">EPSILON</span>); <span class="comment">// 2.220446049250313e-16</span></span><br></pre></td></tr></table></figure>

<p> <strong>2.Number.isNaN:检测一个值是否为NaN</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Number</span>.<span class="built_in">isNaN</span>(<span class="title class_">NaN</span>)); <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<p> <strong>3.Number.isInteger:判断一个数是否为整数</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Number</span>.<span class="title function_">isInteger</span>(<span class="number">1.9</span>)); <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

<p> <strong>4.Math.trunc:将数字的小数部分抹掉</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Math</span>.<span class="title function_">trunc</span>(<span class="number">1.9</span>)); <span class="comment">// 1</span></span><br></pre></td></tr></table></figure>

<h2 id="对象方法扩展"><a href="#对象方法扩展" class="headerlink" title="对象方法扩展"></a>对象方法扩展</h2><p><strong>1.Object.is:判断两个值是否相等</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> a = &#123;&#125;;</span><br><span class="line"><span class="keyword">let</span> b = &#123;&#125;;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Object</span>.<span class="title function_">is</span>(a,b)); <span class="comment">// fakse</span></span><br></pre></td></tr></table></figure>

<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> a = &#123;&#125;;</span><br><span class="line"><span class="keyword">let</span> b = a;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Object</span>.<span class="title function_">is</span>(a,b)); <span class="comment">// true</span></span><br></pre></td></tr></table></figure>



<p> <strong>2.Object.assign:对象的合并</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> a = &#123;<span class="attr">age</span>:<span class="number">19</span>&#125;;</span><br><span class="line"><span class="keyword">let</span> b = &#123;<span class="attr">name</span>: <span class="string">&quot;a&quot;</span>&#125;;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title class_">Object</span>.<span class="title function_">assign</span>(a,b)) <span class="comment">// &#123; age: 19, name: &#x27;a&#x27; &#125;</span></span><br></pre></td></tr></table></figure>



<p> <strong>3.Object.setPrototypeOf:设置原型对象</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//构造函数</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">Person</span>(<span class="params">name</span>) &#123;</span><br><span class="line">    <span class="variable language_">this</span>.<span class="property">name</span> = name;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// var p = new Person(&quot;zhenglijing&quot;);</span></span><br><span class="line"><span class="comment">// 等同于将构造函数的原型对象赋给实例对象p的属性__proto__</span></span><br><span class="line">p.<span class="property">__proto__</span> = <span class="title class_">Object</span>.<span class="title function_">setPrototypeOf</span>(&#123;&#125;,<span class="title class_">Person</span>.<span class="property"><span class="keyword">prototype</span></span>);</span><br><span class="line"><span class="comment">// 通过类调用实例方法</span></span><br><span class="line"><span class="title class_">Person</span>.<span class="title function_">call</span>(p,<span class="string">&quot;zhenglijing&quot;</span>);</span><br></pre></td></tr></table></figure>

<h2 id="Es6模块化"><a href="#Es6模块化" class="headerlink" title="Es6模块化"></a>Es6模块化</h2><p><strong>暴露模块</strong></p>
<p>1、分别暴露：就是在每个需要暴露的变量前加export</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span>  <span class="keyword">let</span> mi = <span class="string">&#x27;xiaomi&#x27;</span></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">function</span> <span class="title function_">name</span>(<span class="params"></span>) &#123;</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">111</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>2、统一暴露</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> mi = <span class="string">&#x27;xiaomi&#x27;</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">name</span>(<span class="params"></span>) &#123;</span><br><span class="line">  <span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="number">111</span>)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">export</span> &#123;mi,name&#125;</span><br></pre></td></tr></table></figure>

<p>3、默认暴露</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">  <span class="attr">mi</span>:<span class="string">&#x27;xiaomi&#x27;</span>,</span><br><span class="line">  <span class="attr">name</span>:<span class="keyword">function</span> &#123;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p><strong>引入模块</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>通用导入模块：<span class="keyword">import</span> * <span class="keyword">as</span> m <span class="keyword">from</span> ‘/xx.<span class="property">js</span>’,其中用<span class="keyword">as</span>定义别名为m。</span><br><span class="line"></span><br><span class="line"><span class="number">2.</span>解构赋值：<span class="keyword">import</span> &#123;a,b <span class="keyword">as</span> c&#125; <span class="keyword">from</span> ‘/xx.<span class="property">js</span>’ 如果多个引入的值中有重复的会报错，可以用<span class="keyword">as</span>如把b的值换成c，</span><br><span class="line">在默认暴露<span class="keyword">default</span>的引入中：<span class="keyword">import</span> &#123; <span class="keyword">default</span> <span class="keyword">as</span> s2&#125;，不能使用<span class="keyword">default</span>，需要用<span class="keyword">as</span>把<span class="keyword">default</span>重定义一个值s2</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span>只有默认暴露可以使用简便的方法：<span class="keyword">import</span> m <span class="keyword">from</span> ‘/xx.<span class="property">js</span>’</span><br></pre></td></tr></table></figure>

<h2 id="async和await"><a href="#async和await" class="headerlink" title="async和await"></a>async和await</h2><p>async用于申明function异步，await用于等待一个异步方法执行完成</p>
<h4 id="async"><a href="#async" class="headerlink" title="async"></a>async</h4><p><strong>1.async函数返回一个 Promise 对象</strong></p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//一个普通函数</span></span><br><span class="line"><span class="keyword">function</span> <span class="title function_">getData</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;syy&quot;</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">getData</span>())  <span class="comment">//syy</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">//加上async后</span></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> <span class="title function_">getData</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;syy&quot;</span>;</span><br><span class="line">&#125;</span><br><span class="line"><span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="title function_">getData</span>());  <span class="comment">//Promise &#123;&lt;resolved&gt;: &quot;syy&quot;&#125;</span></span><br></pre></td></tr></table></figure>

<p><strong>2、async函数内部return语句返回的值，会成为then方法回调函数的参数</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">async function <span class="title function_">getData</span><span class="params">()</span>&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="string">&quot;syy&quot;</span>;</span><br><span class="line">&#125;</span><br><span class="line">getData().then(data=&gt;&#123;</span><br><span class="line">    console.log(data)  <span class="comment">//syy</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<p><strong>3、async函数内部抛出错误，会导致返回的 Promise 对象变为reject状态，抛出的错误对象会被catch方法回调函数接收到</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">async function <span class="title function_">getData</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">Error</span>(<span class="string">&#x27;出错了&#x27;</span>);</span><br><span class="line">&#125;</span><br><span class="line">getData()</span><br><span class="line">.then(</span><br><span class="line">    v =&gt; console.log(v),</span><br><span class="line">    e =&gt; console.log(e)   <span class="comment">//Error: 出错了</span></span><br><span class="line">)</span><br></pre></td></tr></table></figure>



<h4 id="await"><a href="#await" class="headerlink" title="await"></a>await</h4><p>1.await必须放在async中。<br>2.await右侧一般都是promise对象。<br>3.await一般返回的都是promise成功过的值<br>4.await的promise失败了，会抛出异常需要try-catch进行捕获</p>
<blockquote>
<p>正常情况下，await命令后面是一个Promise对象。如果不是，会被转成一个立即resolve的Promise对象。</p>
</blockquote>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> <span class="title function_">getData</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="keyword">return</span> <span class="keyword">new</span> <span class="title class_">Promise</span>(<span class="function">(<span class="params">resolve,reject</span>)=&gt;</span>&#123;</span><br><span class="line">        <span class="built_in">setTimeout</span>(<span class="function">()=&gt;</span>&#123;</span><br><span class="line">            <span class="keyword">var</span> name = <span class="string">&quot;syy&quot;</span>;</span><br><span class="line">            <span class="title function_">resolve</span>(name)</span><br><span class="line">        &#125;,<span class="number">1000</span>)</span><br><span class="line">    &#125;)</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> <span class="title function_">test</span>(<span class="params"></span>)&#123;</span><br><span class="line">    <span class="comment">// await</span></span><br><span class="line">    <span class="keyword">var</span> p = <span class="keyword">await</span> <span class="title function_">getData</span>();</span><br><span class="line">    <span class="variable language_">console</span>.<span class="title function_">log</span>(p);</span><br><span class="line">&#125;;</span><br><span class="line"><span class="title function_">test</span>(); <span class="comment">//syy</span></span><br></pre></td></tr></table></figure>







<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_40322724/article/details/113919534?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168371604816800213024313%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=168371604816800213024313&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-113919534-null-null.142%5Ev86%5Einsert_down1,239%5Ev2%5Einsert_chatgpt&utm_term=es6%E8%AF%AD%E6%B3%95&spm=1018.2226.3001.4187">参考1</a></p>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_58748792/article/details/128939637">参考2</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="https://gitee.com/CWH6">cwh</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://gitee.com/CWH6/2023/05/10/%E3%80%90ES6%E3%80%91ES6%E8%AF%AD%E6%B3%95/">https://gitee.com/CWH6/2023/05/10/%E3%80%90ES6%E3%80%91ES6%E8%AF%AD%E6%B3%95/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/bk/tags/ES6/">ES6</a></div><div class="post_share"><div class="social-share" data-image="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/bk/2023/05/10/%E3%80%90Seata%E3%80%91seata%E7%9A%84%E9%83%A8%E7%BD%B2%E4%B8%8E%E9%9B%86%E6%88%90/" title="【Seata】seata的部署与集成"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">【Seata】seata的部署与集成</div></div></a></div><div class="next-post pull-right"><a href="/bk/2023/05/10/%E3%80%90k3s%E3%80%91K3sa%E5%AE%89%E8%A3%85%E4%B8%8E%E9%83%A8%E7%BD%B2/" title="【k3s】K3s安装与部署"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">【k3s】K3s安装与部署</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/xhs.png" onerror="this.onerror=null;this.src='/bk/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">cwh</div><div class="author-info__description">新博客地址：http://cwh6.gitee.io/vuepressv2/</div></div><div class="card-info-data site-data is-center"><a href="/bk/archives/"><div class="headline">Articles</div><div class="length-num">66</div></a><a href="/bk/tags/"><div class="headline">Tags</div><div class="length-num">33</div></a><a href="/bk/categories/"><div class="headline">Categories</div><div class="length-num">8</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="mailto:2747758546@qq.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a><a class="social-icon" href="https://cwh6-bucket.oss-cn-shanghai.aliyuncs.com/bk/wx_self.jpg" target="_blank" title="wx"><i class="fas fa-qq" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content">ありがとう、私の暗い世界の小さな太陽、ありがとう、ずっと温めてくれた</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#let%E5%AE%9A%E4%B9%89%E5%8F%98%E9%87%8F"><span class="toc-number">1.</span> <span class="toc-text">let定义变量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#const-%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">2.</span> <span class="toc-text">const 关键字</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%93%E6%9E%84%E8%B5%8B%E5%80%BC"><span class="toc-number">3.</span> <span class="toc-text">结构赋值</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A8%A1%E6%9D%BF%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">4.</span> <span class="toc-text">模板字符串</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%80%E5%8C%96%E5%AF%B9%E8%B1%A1%E5%86%99%E6%B3%95"><span class="toc-number">5.</span> <span class="toc-text">简化对象写法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%AD%E5%A4%B4%E5%87%BD%E6%95%B0"><span class="toc-number">6.</span> <span class="toc-text">箭头函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#rest%E5%8F%82%E6%95%B0"><span class="toc-number">7.</span> <span class="toc-text">rest参数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#spread-%E6%8B%93%E5%B1%95%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">8.</span> <span class="toc-text">spread 拓展运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#for%E2%80%A6of%E5%BE%AA%E7%8E%AF"><span class="toc-number">9.</span> <span class="toc-text">for…of循环</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Promise%E5%AF%B9%E8%B1%A1"><span class="toc-number">10.</span> <span class="toc-text">Promise对象</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#set-%E9%9B%86%E5%90%88"><span class="toc-number">11.</span> <span class="toc-text">set 集合</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Map"><span class="toc-number">12.</span> <span class="toc-text">Map</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Class%E7%B1%BB"><span class="toc-number">13.</span> <span class="toc-text">Class类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E5%80%BC%E6%8B%93%E5%B1%95"><span class="toc-number">14.</span> <span class="toc-text">数值拓展</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95%E6%89%A9%E5%B1%95"><span class="toc-number">15.</span> <span class="toc-text">对象方法扩展</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Es6%E6%A8%A1%E5%9D%97%E5%8C%96"><span class="toc-number">16.</span> <span class="toc-text">Es6模块化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#async%E5%92%8Cawait"><span class="toc-number">17.</span> <span class="toc-text">async和await</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#async"><span class="toc-number">17.0.1.</span> <span class="toc-text">async</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#await"><span class="toc-number">17.0.2.</span> <span class="toc-text">await</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2024/02/05/SpringIOC%E7%9A%84%E7%90%86%E8%A7%A3/" title="SpringIOC的理解">SpringIOC的理解</a><time datetime="2024-02-05T14:26:55.000Z" title="Created 2024-02-05 22:26:55">2024-02-05</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2024/01/18/%E3%80%90ai%E3%80%91chatgpt%E7%BB%95%E5%BC%80%E6%A3%80%E6%9F%A5%E8%BF%87%E6%BB%A4/" title="【ai】chatgpt绕开检查过滤">【ai】chatgpt绕开检查过滤</a><time datetime="2024-01-18T15:55:53.000Z" title="Created 2024-01-18 23:55:53">2024-01-18</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2024/01/15/%E3%80%90ai%E6%A8%A1%E5%9E%8B%E3%80%91%E5%88%A4%E6%96%AD%E8%AF%AD%E5%8F%A5%E7%9A%84%E7%A7%AF%E6%9E%81%E6%80%A7%E4%B8%8E%E6%B6%88%E6%9E%81%E6%80%A7/" title="【ai模型】判断语句的积极性与消极性">【ai模型】判断语句的积极性与消极性</a><time datetime="2024-01-15T13:10:14.000Z" title="Created 2024-01-15 21:10:14">2024-01-15</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2023/12/21/%E3%80%90%E5%8C%BA%E5%9D%97%E9%93%BE%E3%80%91%E4%BB%A5%E5%A4%AA%E5%9D%8A%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6/" title="【区块链】以太坊智能合约">【区块链】以太坊智能合约</a><time datetime="2023-12-21T13:36:30.000Z" title="Created 2023-12-21 21:36:30">2023-12-21</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/bk/2023/12/21/%E3%80%90Activiti7%E3%80%91%E5%B7%A5%E4%BD%9C%E6%B5%81%E4%BD%BF%E7%94%A8/" title="【Activiti7】工作流使用">【Activiti7】工作流使用</a><time datetime="2023-12-21T13:21:01.000Z" title="Created 2023-12-21 21:21:01">2023-12-21</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By cwh</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/bk/js/utils.js"></script><script src="/bk/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script id="click-show-text" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-show-text.min.js" data-mobile="false" data-text="offer" data-fontsize="15px" data-random="false" async="async"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>